package com.wz.common.bean;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: wz_api - PageMap
 * <p>Powered by pisces On 2022-01-13 22:13:29
 * <P>Created by IntelliJ IDEA
 *
 * @author ww606851@163.com
 * @version 1.0
 * @description:
 * @since 8
 */

@Data
public class PageMap extends HashMap {

    private final String PAGENUM = "pageNum";
    private final String PAGESIZE = "pageSize";

    int pageNum;
    int pageSize;

    public PageMap(Map map) {
        // 将传递过来的参数放入pageMap中
        this.putAll(map);
        setPageNum(getIntValue(PAGENUM,1));
        put(PAGENUM,getPageNum());
        setPageSize(getIntValue(PAGESIZE,10));
        put(PAGESIZE,getPageSize());

    }
    public PageMap(){}

    /**
     * 取出当前map中的值
     * @param key map中的key
     * @param defaultValue  默认值
     * @return int
     **/

    int getIntValue(String key, int defaultValue) {
        if (!containsKey(key)) return defaultValue;
        Object obj = get(key);
        return obj == null ? defaultValue : Integer.parseInt(obj.toString());
    }

    public int getPageNum() {
        return pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }
}
